<!DOCTYPE html>
<html>

<include file="Public:header" />
<form action="{:U('channel/add_')}" method="post" enctype="multipart/form-data">
    <table class="table table-bordered table-hover definewidth m10">
        <input type="hidden" name="product" value="{$product}"/>
        <tr>
            <td width="10%" class="tableleft">公司名称</td>
            <td>
                <input type="text" name="name" />
            </td>
        </tr>

        <tr>
            <td class="tableleft">同步地址</td>
            <td>
                <input type="text" name="sync_url" />
            </td>
        </tr>

        <tr>
            <td class="tableleft">备注</td>
            <td>
                <input type="text" name="description" />
            </td>
        </tr>
        <!--<tr>-->
            <!--<td class="tableleft">备注</td>-->
            <!--<td>-->
                <!--<select class="selectpicker" data-style="btn-primary" name="product">-->
                    <!--<option  value="1">挖哇</option>-->
                    <!--<option  value="2">余音</option>}-->
                   <!---->
                <!--</select>-->
            <!--</td>-->
        <!--</tr>-->
      
</form>
</td>
</tr>
<tr>
    <td class="tableleft"></td>
    <td>
        <button type="submit" class="btn btn-primary" type="button">保存</button>&nbsp;&nbsp;
        <button type="button" class="btn btn-success" name="backid" id="backid">返回列表</button>
    </td>
</tr>
</table>
</form>
</body>

</html>
<script>
$(function() {
    $('#backid').click(function() {
        window.location.href = "index.html";
    });


    $("#addImage").on('click', function() {
        $('<input />', {
            id: 'cbx',
            name: 'images[]',
            type: 'file',
           
        }).appendTo($('#cimages'));
    });
    /* 上传 */
    $(".fileinput").on("click", function() {

        var that = $(this),
            format = that.attr("format").split("/"),
            filebox = that.parent("div"),
            filetext = filebox.prev(".file-path"),
            loadtip = that.prev("span"),
            pbtn = filebox.next(".handle").find('.lodebtn'),
            text = loadtip.html(),
            date = Date.parse(new Date());

        if (that.attr("loading") == 1) {
            alert("正在上传,请稍后");
            return false;
        }


        $(".uploaddom", filebox).remove();
        var $filedom = $('<div class="uploaddom hide"><iframe id="upload_page' + date + '" name="upload_page' + date + '" class="upload_page"></iframe><form class="file_form" action="http://wawa.fm:9090/fileserver/FileServer.php" method="post" enctype="multipart/form-data" target="upload_page' + date + '"><input class="uploadfile" type="file" name="uploadfile" /></form></div>');
        filebox.append($filedom);


        var $uploadfile = $(".uploadfile", filebox),
            $file_form = $(".file_form", filebox),
            $upload_page = $(".upload_page", filebox);

        $uploadfile.unbind('change').trigger('click');
        $upload_page.unbind('load');
        $upload_page[0].contentDocument.body.innerHTML = '';

        $uploadfile.on("change", function() {

            var finput = $(this),
                filename = finput.val().replace(/.*(\/|\\)/, ""),
                fileExt = (/[.]/.exec(filename)) ? /[^.]+$/.exec(filename.toLowerCase()) : '',
                isType = false;

            if (finput.val() == '') {
                return false;
            }

            for (var i = 0; i < format.length; i++) {
                if (fileExt == format[i]) {
                    isType = true;
                }
            }

            if (!isType) {
                alert("请上传格式为" + format + "的文件");
                return false;
            } else {
                that.attr("loading", "1");
                $file_form.submit();
                loadtip.html("上传中...");
                filebox.css("background", "#999");
                $upload_page.load(function() {
                    // alert($(this)[0].srcdoc);
                    // return;

                    var $innerhtml = $(this)[0].contentWindow.body.innerHTML;
                    if ($innerhtml != undefined) {

                        res = eval('(' + $innerhtml.substring($innerhtml.indexOf("{"), $innerhtml.lastIndexOf("}") + 1) + ')');
                        if (res.status == 1) {
                            var url = res.url,
                                preview_url = res.preview_url,
                                thumbnail = res.thumbnail,
                                suffix = res.suffix,
                                time = res.fileinfo && parseInt(res.fileinfo.filetime) * 1000;
                            size = res.fileinfo && parseInt(res.fileinfo.filesize);
                            pbtn.attr({
                                "thumbnail": thumbnail,
                                "href": preview_url
                            }).animate({
                                "opacity": "1"
                            }).find("input").attr({
                                "value": url,
                                "thumbnail": thumbnail,
                                "filetime": time,
                                "filesize": size
                            });
                            filebox.css("background", "#26a69a");
                            loadtip.html(text);
                        } else {
                            alert("上传失败" + res.info);
                        }
                        that.attr("loading", "0");
                    }
                })
            }


        })
        return false;
    });



});
</script>
<script>
$(function() {
    $('#backid').click(function() {
        window.location.href = "{:U('channel/list_',array('product'=>$product))}";
    });

});
</script>
